<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Narayana启动-注册恢复模块流程 | flyingzc's blog</title><meta name="author" content="flyingzc"><meta name="copyright" content="flyingzc"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Narayana启动-注册恢复模块流程使用代码12&#x2F;&#x2F; narayana 在启动阶段使用如下 api 加载恢复模块XARecoveryModulexaRecoveryModule &#x3D; XARecoveryModule.getRegisteredXARecoveryModule();  总体流程1234567891011121314151617注册恢复模块    反射创建 RecoveryEnvir">
<meta property="og:type" content="article">
<meta property="og:title" content="Narayana启动-注册恢复模块流程">
<meta property="og:url" content="https://flyingzc.github.io/articles/narayana/narayana02-init-jdbc.html">
<meta property="og:site_name" content="flyingzc&#39;s blog">
<meta property="og:description" content="Narayana启动-注册恢复模块流程使用代码12&#x2F;&#x2F; narayana 在启动阶段使用如下 api 加载恢复模块XARecoveryModulexaRecoveryModule &#x3D; XARecoveryModule.getRegisteredXARecoveryModule();  总体流程1234567891011121314151617注册恢复模块    反射创建 RecoveryEnvir">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://flyingzc.github.io/images/zc-icon.jpeg">
<meta property="article:published_time" content="2023-12-06T16:00:00.000Z">
<meta property="article:modified_time" content="2025-01-21T01:51:41.212Z">
<meta property="article:author" content="flyingzc">
<meta property="article:tag" content="Transaction">
<meta property="article:tag" content="Narayana">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://flyingzc.github.io/images/zc-icon.jpeg"><script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "Narayana启动-注册恢复模块流程",
  "url": "https://flyingzc.github.io/articles/narayana/narayana02-init-jdbc.html",
  "image": "https://flyingzc.github.io/images/zc-icon.jpeg",
  "datePublished": "2023-12-06T16:00:00.000Z",
  "dateModified": "2025-01-21T01:51:41.212Z",
  "author": [
    {
      "@type": "Person",
      "name": "flyingzc",
      "url": "https://flyingzc.github.io/"
    }
  ]
}</script><link rel="shortcut icon" href="/images/zc-icon.jpeg"><link rel="canonical" href="https://flyingzc.github.io/articles/narayana/narayana02-init-jdbc.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="DentpX3LnP_WNgEeFnNIcTZZky-Bby-zL-uI_9GqTAw"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!false && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script>(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: '',
  enable_page_level_ads: 'true'
});</script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":false},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyloadPlugin: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Narayana启动-注册恢复模块流程',
  isHighlightShrink: false,
  isToc: true,
  pageType: 'post'
}</script><link rel="stylesheet" href="/self/github-dark.css"><meta name="generator" content="Hexo 7.0.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img text-center"><img src="/images/zc-icon.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data text-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">84</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">29</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">flyingzc's blog</span></a><a class="nav-page-title" href="/"><span class="site-name">Narayana启动-注册恢复模块流程</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">Narayana启动-注册恢复模块流程</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-12-06T16:00:00.000Z" title="发表于 2023-12-07 00:00:00">2023-12-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-01-21T01:51:41.212Z" title="更新于 2025-01-21 09:51:41">2025-01-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Narayana/">Narayana</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="container post-content" id="article-container"><h1 id="Narayana启动-注册恢复模块流程"><a href="#Narayana启动-注册恢复模块流程" class="headerlink" title="Narayana启动-注册恢复模块流程"></a>Narayana启动-注册恢复模块流程</h1><h2 id="使用代码"><a href="#使用代码" class="headerlink" title="使用代码"></a>使用代码</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// narayana 在启动阶段使用如下 api 加载恢复模块</span><br>XARecoveryModulexaRecoveryModule = XARecoveryModule.getRegisteredXARecoveryModule();<br></code></pre></td></tr></table></figure>

<h2 id="总体流程"><a href="#总体流程" class="headerlink" title="总体流程"></a>总体流程</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs km">注册恢复模块<br>    反射创建 RecoveryEnvironmentBean 配置信息实例<br>    加载 RecoveryActivators<br>    启动 RecoveryActivators<br>    初始化 PeriodicRecovery<br>        设置恢复状态 INACTIVE<br>        设置恢复mode ENABLED<br>    加载恢复模块，module包括:<br>    1.com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule<br>    2.com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule<br>    反射实例化并初始化 上面的 AtomicActionRecoveryModule 和 XARecoveryModule<br>        1.反射实例化 AtomicActionRecoveryModule<br>            AtomicActionRecoveryModule 构造方法里初始化 storeManager<br>            获取存储类型，此处是文件存储 ShadowNoFileLockStore<br>            实例化存储，此处是 ShadowNoFileLockStore-&gt;父类ShadowingStore-&gt;父类FileSystemStore-&gt;父类 ObjectStore<br>            从文件路径中恢复事务存储信息<br>        2.反射实例化 XARecoveryModule<br></code></pre></td></tr></table></figure>

<h3 id="调用链路"><a href="#调用链路" class="headerlink" title="调用链路"></a>调用链路</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs km">com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule#getRegisteredXARecoveryModule<br>注册恢复模块<br>    com.arjuna.ats.arjuna.recovery.RecoveryManager#manager<br>        com.arjuna.ats.arjuna.recovery.RecoveryManager#manager<br>            com.arjuna.ats.arjuna.common.recoveryPropertyManager#getRecoveryEnvironmentBean<br>            反射创建 RecoveryEnvironmentBean 配置信息实例<br>                com.arjuna.common.internal.util.propertyservice.BeanPopulator#getDefaultInstance<br>            com.arjuna.ats.internal.arjuna.recovery.RecActivatorLoader#loadRecoveryActivators<br>            加载 RecoveryActivators<br>                com.arjuna.ats.arjuna.common.recoveryPropertyManager#getRecoveryEnvironmentBean<br>            com.arjuna.ats.internal.arjuna.recovery.RecActivatorLoader#startRecoveryActivators<br>            启动 RecoveryActivators<br>            com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#initialise<br>            初始化 PeriodicRecovery<br>                com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#setStatus<br>                设置恢复状态 INACTIVE<br>                com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery#setMode<br>                设置恢复mode ENABLED<br>            internal.arjuna.recovery.PeriodicRecovery#loadModules<br>            加载恢复模块，module包括:<br>            1.com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule<br>            2.com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule<br>                com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean#getRecoveryModules<br>                    com.arjuna.common.internal.util.ClassloadingUtility#loadAndInstantiateClassesWithInit<br>                    反射实例化并初始化 上面的 AtomicActionRecoveryModule 和 XARecoveryModule<br>                        com.arjuna.common.internal.util.ClassloadingUtility#loadAndInstantiateClass<br>                        1.反射实例化 AtomicActionRecoveryModule<br>                            com.arjuna.ats.arjuna.objectstore.StoreManager#getRecoveryStore<br>                            AtomicActionRecoveryModule 构造方法里初始化 storeManager<br>                                com.arjuna.ats.arjuna.objectstore.StoreManager#getActionStore<br>                                    com.arjuna.ats.arjuna.objectstore.StoreManager#initStore<br>                                        com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean#getObjectStoreType<br>                                        获取存储类型，此处是文件存储 com.arjuna.ats.internal.arjuna.objectstore.ShadowNoFileLockStore<br>                                        com.arjuna.common.internal.util.ClassloadingUtility#loadAndInstantiateClass<br>                                        实例化存储，此处是 com.arjuna.ats.internal.arjuna.objectstore.ShadowNoFileLockStore-&gt;父类ShadowingStore-&gt;父类FileSystemStore-&gt;父类 ObjectStore<br>                            com.arjuna.ats.arjuna.recovery.TransactionStatusConnectionManager#updateTSMI<br>                            从文件路径中恢复事务存储信息<br>                        com.arjuna.common.internal.util.ClassloadingUtility#loadAndInstantiateClass<br>                        2.反射实例化 XARecoveryModule<br>                            com.arjuna.common.internal.util.ClassloadingUtility#loadClass<br>                            com.arjuna.ats.arjuna.objectstore.StoreManager#getRecoveryStore<br>                            com.arjuna.ats.jta.common.JTAEnvironmentBean#getXaResourceOrphanFilters<br>                            com.arjuna.ats.internal.jta.Implementations#initialise<br>            com.arjuna.ats.internal.arjuna.recovery.ExpiredEntryMonitor#startUp<br>                com.arjuna.ats.internal.arjuna.recovery.ExpiredEntryMonitor#initialise<br></code></pre></td></tr></table></figure>
<link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/markmap-toolbar@0.18.10/dist/style.css"><script src="https://fastly.jsdelivr.net/npm/d3@7"></script><script src="https://fastly.jsdelivr.net/npm/markmap-view@0.18.10"></script><script src="https://fastly.jsdelivr.net/npm/markmap-toolbar@0.18.10"></script>
<link rel="stylesheet" href="/css/markmap.css">

<script src="/js/markmap.js"></script>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://flyingzc.github.io">flyingzc</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://flyingzc.github.io/articles/narayana/narayana02-init-jdbc.html">https://flyingzc.github.io/articles/narayana/narayana02-init-jdbc.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="https://flyingzc.github.io" target="_blank">flyingzc's blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Transaction/">Transaction</a><a class="post-meta__tags" href="/tags/Narayana/">Narayana</a></div><div class="post-share"><div class="social-share" data-image="/images/zc-icon.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a class="pagination-related" href="/articles/narayana/narayana01-init.html" title="Narayana 事务管理器初始化流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-06</div><div class="info-item-2">Narayana 事务管理器初始化流程</div></div><div class="info-2"><div class="info-item-1">事务管理器初始化流程总体流程12345678910创建 TransactionManagerImple    创建事务管理器对象读取 narayana 的 xml 配置，进行属性赋值获取 recovery 模块    加载恢复模块事务恢复日志的初始化初始化事务日志存储服务    JDBC方式存储        建表	文件方式存储  创建 TransactionManager 流程Narayana 会通过 BeanPopulator 反射创建对应的 TransactionManager 实例，并读取用户自定义的 xml 属性反射赋值到 TransactionManager 实例里。 1TransactionManager transactionManager =...</div></div></div></a><a class="pagination-related" href="/articles/narayana/narayana03-begin.html" title="Narayana 事务 begin 流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-08</div><div class="info-item-2">Narayana 事务 begin 流程</div></div><div class="info-2"><div class="info-item-1">Narayana 事务 begin 流程整体流程12345检查事务状态获取超时时间创建事务对象    事务对象设置到 ThreadLocal 中,和当前线程绑定    插入事务测超时时间监控  使用 API123TransactionManager transactionManager = jtaPropertyManager.getJTAEnvironmentBean().getTransactionManager();// 开启全局事务transactionManager.begin();  调用链路123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869internal.jta.transaction.arjunacore.BaseTransaction#begin开启事务   ...</div></div></div></a><a class="pagination-related" href="/articles/narayana/narayana04-enlistResource.html" title="Narayana 事务资源注册流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-08</div><div class="info-item-2">Narayana 事务资源注册流程</div></div><div class="info-2"><div class="info-item-1">Narayana enlistResource流程XA 事务内每个物理连接执行第一条物理 sql 之前,需要执行 xa start 操作开启每个RM分支上的 xa 事务,并将 xaResource 注册到 TransactionManager 里。 整体流程12345678910transaction.enlistResource(xaResource)    执行 XA start xid        遍历 resource 判断当前是 isNewRM        创建 xid        createRecord        theTransaction.add(abstractRecord)            record 添加到 BasicAction.RecordList 里        执行 xa start 语句,若失败重试            MysqlXAConnection#start    把 XAResource 缓存到 map  使用1234567// 获取 XADataSourceXADataSource xaDatasource =...</div></div></div></a><a class="pagination-related" href="/articles/narayana/narayana05-commit.html" title="Narayana 事务 Commit 流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-11</div><div class="info-item-2">Narayana 事务 Commit 流程</div></div><div class="info-2"><div class="info-item-1">Narayana commit 流程整体流程123456789101112131415161718192021222324事务提交    判断是否能进行一阶段提交优化        若能一阶段提交            执行一阶段提交        否则            二阶段提交                prepare阶段                    执行 xa end                    执行 xa prepare                        xaResourceRecord 插入到 preparedList                            BasicAction#insertRecord                        更新状态 ActionStatus.COMMITTING                        保存状态，打包状态到 outputBuffer 里                            XAResourceRecord#save_state...</div></div></div></a><a class="pagination-related" href="/articles/narayana/narayana06-recovery.html" title="Narayana 事务恢复流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-12</div><div class="info-item-2">Narayana 事务恢复流程</div></div><div class="info-2"><div class="info-item-1">Narayana 事务恢复流程总体流程123456789101112131415恢复线程轮询1.判断是否有任务要处理2.若有任务要处理,则处理    1.获取所有配置的 recovery modules    2.遍历recovery modules,执行一阶段处理        XARecoveryModule:             执行 XA recovery 命令从 RM 中获取 prepare 状态的 XID 数组并缓存        AtomicActionRecoveryModule:            从事务日志中,获取需要恢复的 XID 数组并缓存    3.遍历recovery modules,执行二阶段处理        AtomicActionRecoveryModule:            1.根据状态判断是否需要执行二阶段的 commit 或 rollback            2.清理事务 recovery 日志        XARecoveryModule:           ...</div></div></div></a><a class="pagination-related" href="/articles/narayana/narayana07-rollback.html" title="Narayana 事务回滚流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-13</div><div class="info-item-2">Narayana 事务回滚流程</div></div><div class="info-2"><div class="info-item-1">Narayana 事务回滚流程当用户手动调用 connection.rollback() 回滚当前全局事务时，会走如下流程。 总体流程1234遍历每个 resource    执行 xa end;    执行 xa rollback;清理缓存  使用1234567TransactionManager transactionManager = jtaPropertyManager.getJTAEnvironmentBean().getTransactionManager();// 开启事务transactionManager.begin();// 执行 sql 语句// ...//...</div></div></div></a></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info text-center"><div class="avatar-img"><img src="/images/zc-icon.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">flyingzc</div><div class="author-info-description">不积跬步无以至千里<br/>不积小流无以成江海</div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">84</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">29</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/FlyingZC"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons"><a class="social-icon" href="https://github.com/FlyingZC" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">FlyingZC's Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Narayana%E5%90%AF%E5%8A%A8-%E6%B3%A8%E5%86%8C%E6%81%A2%E5%A4%8D%E6%A8%A1%E5%9D%97%E6%B5%81%E7%A8%8B"><span class="toc-number">1.</span> <span class="toc-text">Narayana启动-注册恢复模块流程</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E4%BB%A3%E7%A0%81"><span class="toc-number">1.1.</span> <span class="toc-text">使用代码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E4%BD%93%E6%B5%81%E7%A8%8B"><span class="toc-number">1.2.</span> <span class="toc-text">总体流程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B0%83%E7%94%A8%E9%93%BE%E8%B7%AF"><span class="toc-number">1.2.1.</span> <span class="toc-text">调用链路</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite03-transaction-begin.html" title="Apache Ignite 开启事务执行流程">Apache Ignite 开启事务执行流程</a><time datetime="2025-10-10T16:00:00.000Z" title="发表于 2025-10-11 00:00:00">2025-10-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite02-transaction.html" title="Apache Ignite 分布式事务原理">Apache Ignite 分布式事务原理</a><time datetime="2025-09-17T16:00:00.000Z" title="发表于 2025-09-18 00:00:00">2025-09-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite01-build.html" title="Apache Ignite IDEA 环境搭建">Apache Ignite IDEA 环境搭建</a><time datetime="2025-09-10T16:00:00.000Z" title="发表于 2025-09-11 00:00:00">2025-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/druid/druid01-resultset-leak.html" title="ShardingSphere JDBC 使用 Druid 连接池 ResultSet 内存泄露分析">ShardingSphere JDBC 使用 Druid 连接池 ResultSet 内存泄露分析</a><time datetime="2025-06-30T16:00:00.000Z" title="发表于 2025-07-01 00:00:00">2025-07-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/jmeter/jmeter01-shardingsphere.html" title="Jmeter 压测 ShardingSphere">Jmeter 压测 ShardingSphere</a><time datetime="2025-06-30T16:00:00.000Z" title="发表于 2025-07-01 00:00:00">2025-07-01</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2025 By flyingzc</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>